/*
 * @Author: your name
 * @Date: 2021-05-17 08:11:38
 * @LastEditTime: 2021-05-17 08:54:27
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \api\lib\pages\apis\gest\gest_home_page.dart
 */
import 'package:flutter/material.dart';

class ClipHomePage extends StatefulWidget {
  @override
  _ClipHomePageState createState() => _ClipHomePageState();
}

class _ClipHomePageState extends State<ClipHomePage> {
  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
      appBar: AppBar(title: Text('gridview')),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              width: width,
              height: 300,
              color: Colors.grey,
              alignment: Alignment.center,
              // ClipOval 圆形椭圆形 裁剪
              child: ClipOval(
                // Clip.antiAlias 抗锯齿
                // Clip.none 不裁剪
                // Clip.hardEdge 不抗锯齿
                // Clip.antiAliasWithSaveLayer 抗锯齿并保留图层
                clipBehavior: Clip.antiAlias,
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.blue,
                ),
              ),
            ),
            Container(
              width: width,
              height: 300,
              margin: EdgeInsets.all(20),
              color: Colors.grey,
              alignment: Alignment.center,
              // ClipRect 矩形
              child: ClipRect(
                clipBehavior: Clip.antiAlias,
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.blue,
                ),
              ),
            ),
            Container(
              width: width,
              height: 300,
              margin: EdgeInsets.all(20),
              color: Colors.grey,
              alignment: Alignment.center,
              // ClipRect 矩形
              child: ClipRRect(
                borderRadius: BorderRadius.all(Radius.circular(10)),
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.blue,
                ),
              ),
            ),
            Container(
              width: width,
              height: 300,
              margin: EdgeInsets.all(20),
              color: Colors.grey,
              alignment: Alignment.center,
              // ClipRect 矩形
              child: ClipPath(
                clipper: CustomPathClip(),
                child: Container(
                  width: 200,
                  height: 200,
                  color: Colors.blue,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

// 自定义绘制裁剪形状
class CustomPathClip extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = new Path();
    path.moveTo(100, 0);
    path.lineTo(150, 100);
    path.lineTo(50, 100);
    path.close();
    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return true;
  }
}
